//my_s.js
//获取应用实例
const app = getApp()
/**
 * 版权：山西书海传媒科技有限责任公司
 * 作者：吕俊雄
 * 更新时间：2019年3月29号
 */
Page({
  data: {
  },
  onLoad: function (options) {
    var that = this;
    wx.showLoading({
      title: '数据初始化中',
    })
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/gian_Username.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        parayId: wx.getStorageSync("shuhai_party_id"),
        //parayId: '374b8c0569d81da50169dbe64ead0000',
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.status == "success") {
          wx.hideLoading();
          that.setData({
            username: res.data.data.result,
          })
        }
      },
      fail: function (res) {
        wx.hideLoading();
        wx.showToast({
          title: '网络错误！',
          icon: 'none',
          duration: 2000
        })
        return;
      }
    });
  },
  //跳转工资查询
  goSalary: function () {
    wx.navigateTo({
      url: '../salary/salary',
    })
  },
  //退出到登录页
  goQuit: function () {
    wx.showLoading({
      title: '退出中',
    })
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/quitLogin.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        openid: wx.getStorageSync("userOpenid")
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.status == "success") {
          wx.redirectTo({
            url: '../login/login'
          })
          wx.hideLoading();
          wx.showToast({
            title: '退出登录成功',
            icon: 'none',
            duration: 2000
          })
          return
        } else {
          wx.redirectTo({
            url: '../login/login'
          })
          wx.hideLoading();
          wx.showToast({
            title: '退出登录成功',
            icon: 'none',
            duration: 2000
          })
          return
        }
      },
      fail: function (res) {
        wx.hideLoading();
        wx.showToast({
          title: '网络错误！',
          icon: 'none',
          duration: 2000
        })
        return;
      }
    });

  },
  // 下拉刷新
  onPullDownRefresh: function () {
    var that = this;
    wx.setNavigationBarTitle({
      title: '出版传媒'
    });
    wx.showNavigationBarLoading(); //在标题栏中显示加载图标
    wx.showLoading({
      title: '数据初始化中',
    })
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/gian_Username.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        parayId: wx.getStorageSync("shuhai_party_id"),
        //parayId: '374b8c0569d81da50169dbe64ead0000',
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.status == "success") {
          wx.hideLoading();
          that.setData({
            username: res.data.data.result,
          })
        }
      },
      fail: function (res) {
        wx.hideLoading();
        wx.showToast({
          title: '网络错误！',
          icon: 'none',
          duration: 2000
        })
        return;
      }, complete: function () {
        wx.hideNavigationBarLoading();                   //完成停止加载
        wx.stopPullDownRefresh();                       //停止下拉刷新
      }
    });
  },
})